Developer Documentation
PATH  Mac OS X Documentation > Developer Tools > Mac OS X Assembler Guide


Previous | Contents | Next

Miscellaneous Directives

This section describes additional directives that don't fit into any of the previous sections.

.abort

SYNOPSIS

.abort [ "abort_string "]

The .abort directive causes the assembler to ignore all further input and quit processing. No files are created. The directive would be used, for example, in a pipe interconnected version of a compiler--the first major syntax error would cause the compiler to issue this directive, saving unnecessary work in assembling code that would have to be discarded anyway.

The optional "abort_string "is printed as part of the error message when the .abort directive is encountered.

EXAMPLE

#ifndef VAR .abort "You must define VAR to assemble this file." #endif

.file and .line

SYNOPSIS

.file file_name .line line_number

The .file directive causes the assembler to report error messages as if it were processing the file file_name .

The .line directive causes the assembler to report error messages as if it were processing the line line_number . The next line after the .line directive is assumed to be line_number .

The assembler turns C preprocessor comments of the form

# line_number file_name level

into

.line line_number ; .file file_name

EXAMPLE

.line 6 nop | this is line 6

.if, .elseif, .else, and .endif

SYNOPSIS

.if expression .elseif expression .else .endif

These directives are used to delimit blocks of code that are to be assembled conditionally, depending on the value of an expression. A block of conditional code may be nested within another block of conditional code. Expression must be an absolute expression.

For each .if directive,

Labels or multiple statements must not be placed on the same line as any of these directives; otherwise, statements including these directives won't be recognized and will produce errors or incorrect conditional assembly.

EXAMPLE

.if a==1 .long 1 .elseif a==2 .long 2 .else .long 3 .endif

.include

SYNOPSIS

.include "filename "

The .include directive causes the named file to be included at the current point in the assembly. The -I dir option to the assembler specifies alternative paths to be used in searching for the file if it isn't found in the current directory (the default path, /usr/include , is always searched last).

EXAMPLE

.include "macros.h"

.macro, .endmacro, .macros_on, and .macros_off

SYNOPSIS

.macro .endmacro .macros_on .macros_off

These directives allow your to define simple macros (once a macro is defined, however, you can't redefine it). For example:

.macro var instruction_1 $0,$1 instruction_2 $2 . . . instruction_N .long $n .endmacro

$d(where dis a single decimal digit, 0 through 9) represents each argument--there can be at most 10 arguments. $n is replaced by the actual number of arguments the macro was invoked with.

When you use a macro, arguments are separated by a comma (except inside matching parentheses--for example, xxx(1,3,4),yyy contains only two arguments). You could use the macro defined above as follows:

var #0,@sp,4

This would be expanded to:

instruction_1 #0,@sp instruction_2 4 . . . instruction_N .long 3

The directives .macros_on and .macros_off allow macros to be written that override an instruction or directive while still using the instruction or directive. For example:

.macro .long .macros_off .long $0,$0 .macros_on .endmacro

If you don't specify an argument, the macro will substitute nothing (also see the .abs directive below).

.abs

SYNOPSIS

.abs symbol_name ,expression

This directive sets the value of symbol_name to 1 if expression is an absolute expression; otherwise, it sets the value to 0.

EXAMPLE

.macro var .abs is_abs,$0 .if is_abs==1 .abort "must be absolute" .endif .endmacro

.dump and .load

SYNOPSIS

.dump filename .load filename

These directives let you dump and load the absolute symbols and macro definitions, for faster loading and faster assembly.

These work like this:

.include "big_file_1" .include "big_file_2" .include "big_file_3" . . . .include "big_file_N" .dump "symbols.dump"

The .dump directive writes out all the N_ABS symbols and macros. You can later use the .load directive to load all the N_ABS symbols and macros faster than you could with .include :

.load "symbols.dump"

One useful side effect of loading symbols this way is that they aren't written out to the object file.


Mac OS X Assembler Guide: ASM Directives

Previous | Contents | Next